package com.fox.imagedb.gui.menu.item;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.KeyStroke;

import com.fox.imagedb.gui.MainPanel;
import com.fox.imagedb.listener.ImageDBMenuListener;

public class OpenMenuItem extends ImageDBMenuItem {

	private static final long serialVersionUID = 3414563687175651904L;

	public OpenMenuItem(MainPanel mainPanel, ImageDBMenuListener menuListener) {
		super(mainPanel);
		setText("Ouvrir...");
		setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
				ActionEvent.CTRL_MASK));
		addActionListener(menuListener);
	}

	@Override
	public void performAction() {
		JFileChooser chooser = new JFileChooser();
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int returnVal = chooser.showOpenDialog(mainPanel);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File image = mainPanel.getFileExplorer().updateWorkingDirectory(
					chooser.getSelectedFile());
			mainPanel.updateImage(image);
		}

	}

}
